/*
============================================================================
 Name        : TCPSocketSender.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CTCPSocketSender declaration
============================================================================
*/

#ifndef TCPSOCKETSENDER_H
#define TCPSOCKETSENDER_H

// For CActive, link against: euser.lib
// For RTimer, link against: euser.lib
#include <e32base.h>
#include <es_sock.h>
#include <in_sock.h>

#include "TCPSocketTimer.h"

class CTCPSocketSender : public CActive, public CTCPSocketTimer::MTimerObserver
{
public: // Observer interface
	class MObserver
	{
	public:
		virtual void OnSendL(const TDesC8& aMsg, TInt aError) = 0;
	};

public:
	static CTCPSocketSender* NewL(MObserver& aObserver, RSocket& aSocket);
	// C++ constructor
	CTCPSocketSender(MObserver& aObserver, RSocket& aSocket);
	void ConstructL();
	// Cancel and destroy
	~CTCPSocketSender();


private: // From CActive
	// Handle completion
	void RunL();
	
	// How to cancel me
	void DoCancel();

protected: // Functions from CTcpSocketTimer::MTimerObserver
	void OnTimerL(TInt aError);	
	// Override to handle leaves from RunL(). Default implementation causes
	// the active scheduler to panic.
	//void RunError(TInt aError);

private: // member variables
	MObserver& iObserver;
	RSocket& iSocket;
	HBufC8* iBufferPtr;
	CTCPSocketTimer* iTimer;

public: // New functions
	void Send(const TDesC8& aMsg);

};

#endif
